﻿
using Microsoft.Extensions.Caching.Memory;
using Modules.MSentEvent;
using Modules.Units;
using Prism.Events;
using Sorting.App.Models;
using Sorting.App.Models.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using Microsoft.Extensions.Logging;
using HslCommunication;
using HslCommunication.Profinet.Melsec;
using System.IO.Ports;
using System.Windows.Media.Animation;

namespace Modules.ActionRun
{
    /// <summary>
    /// 下发PLC动作执行帮助类
    /// </summary>
    public static class ActionRunHelper
    {
        public static ILog _log = LogManager.GetLogger(typeof(ActionRunHelper));

        public static  bool IsCon = false;

        static MelsecFxLinks MelsecPLC = new MelsecFxLinks();//RS485
        private static bool Open()
        {
            MelsecPLC.SerialPortInni(sp =>
            {
                sp.PortName = AppsettingUnits.Appseeting.PlcPort;
                sp.BaudRate = 9600;//波特率
                sp.DataBits = 7;//数据位
                sp.StopBits = StopBits.One;//停止位：1
                sp.Parity = Parity.Odd;//奇偶：奇
            });
            MelsecPLC.Open();
            IsCon = MelsecPLC.IsOpen();
            return IsCon;
        }


        /// <summary>
        /// 方法执行
        /// </summary>
        /// <param name="obj"></param>
        /// <exception cref="NotImplementedException"></exception>
        public static void SentEventExecute(MessageModel model)
        {
            //switch (model.Code)
            //{
            //    //回原点
            //    case EnumMessageType.ME200:
            //        RunBackOrigin(EnumStockGroup.A);
            //        RunBackOrigin(EnumStockGroup.B);
            //        break;
            //    //下发储位
            //    case EnumMessageType.ME201:
            //        var res = (ShelfEntity)model.Data;
            //        RunToLoc(res.Module, (short)Convert.ToInt32(res.Code));
            //        break;

            //    //选择模式
            //    case EnumMessageType.ME202:
            //        SelectPlcModelType(model.Data);
            //        break;

            //    //选择速度挡位
            //    case EnumMessageType.ME203:
            //        SelectPlcGear(model.Data);
            //        break;
            //     //软件启动初始化
            //    case EnumMessageType.ME204:
               
            //        break;
            //    //执行看门狗
            //    case EnumMessageType.ME206:
            //        GetPlcLifeCmd();
            //        break;

            //    //执行软件看门狗
            //    case EnumMessageType.ME207:
                 
            //        break;
                
            //    //开启常驻线程检测
            //    case EnumMessageType.ME205:
                  
            //        break;
            //    //执行输液袋入队信号监控
            //    case  EnumMessageType.ME208:
            
            //        break;
            //    case  EnumMessageType.ME209:
            //        GetbackOrgState();
            //        break;
            //    default:
            //        break;
            //}

        }


        #region 下发PLC指令




        /// <summary>
        /// 选择PLC运行模式
        /// </summary>
        public static void SelectPlcModelType(EnumPlcModelType modelType)
        {

            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.SelectPlcModelType, (short)modelType);

        }


        /// <summary>
        /// 回原点
        /// </summary>
        /// <param name="group"></param>

        public static void RunBackOrigin()
        {
            if (!IsCon)
            {
                Open();
            }
           MelsecPLC.WriteAsync(PLCAddrModel.BackToOrigin, (short)1);
            
        }
        /// <summary>
        /// 开始
        /// </summary>
        public static void Start()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.SelectStartStop, (short)1);
        }

        public static async Task<OperateResult<short[]>> GetRunStatus()
        {
            if (!IsCon)
            {
                Open();
            }
            // short NewStates = 0;
            var NewStates = await MelsecPLC.ReadInt16Async(PLCAddrModel.SelectStartStop, 1);

            return NewStates;


        }

        /// <summary>
        /// 输送带启动
        /// </summary>
        public static void InBeltOn()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.InputKey, (short)1);
        }

        //public async static Task<OperateResult> InputKeyOn()
        //{
        //    if (!ACon)
        //    {
        //        PlcConnectA();
        //    }
        //  var res = await  AFXCPU.WriteAsync(PLCAddrModel.InputKey, (short)1);
        //    return res;
        //}


        //异步停止入口皮带
        public static void InBeltOffAsync()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.InputKey, (short)0);
        }
        //停止入口皮带
        public static void InBeltOff()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.Write(PLCAddrModel.InputKey, (short)0);
        }
        /// <summary>
        /// 停止
        /// </summary>
        public static void Stop()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.SelectStartStop, (short)0);
        }


        public static void SetStartCheck()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.SetStartCheck, (short)1);
        }


        /// <summary>
        /// 写入储位
        /// </summary>
        /// <param name="group"></param>
        /// <param name="addr"></param>
        public static void RunToLoc(int addr)
        {
            if (!IsCon)
            {
                Open();
            }

                var res = MelsecPLC.Write(PLCAddrModel.WriteLoc, (short)addr);
                if (!res.IsSuccess)
                {
                    _log.Error("写入储位"+ addr+"错误");
                }
                else
                {
                    _log.Info("发送地址："+addr);
                }
        }




        #endregion

        #region  调试专用公开方法


        /// <summary>
        /// X轴回原点
        /// </summary>
        /// <param name="group"></param>
        public static void RunXToOrgin()
        {
        }
        /// <summary>
        /// A模组X轴转动，
        /// 0：停止 1：正转 2：反转
        /// </summary>
        /// <param name="module"></param>
        public static void RunModuleAX(int module)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.ModuleAX, (short)module);
        }
        /// <summary>
        /// A模组Z轴转动，
        /// 0：停止 1：正转 2：反转
        /// </summary>
        /// <param name="module"></param>
        public static void RunModuleAZ(int module)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.ModuleAZ, (short)module);
        }
        /// <summary>
        /// B模组X轴转动，
        /// 0：停止 1：正转 2：反转
        /// </summary>
        /// <param name="module"></param>
        public static void RunModuleBX(int module)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.ModuleBX, (short)module);
        }
        /// <summary>
        /// B模组Z轴转动，
        /// 0：停止 1：正转 2：反转
        /// </summary>
        /// <param name="module"></param>
        public static void RunModuleBZ(int module)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.ModuleBZ, (short)module);
        }
        /// <summary>
        /// Z轴回原点
        /// </summary>
        /// <param name="group"></param>
        public static void RunZToOrgin()
        {
        }

        /// <summary>
        /// 输入皮带运行  --调试使用
        /// </summary>
        /// <param name="group"></param>
        public static void RunInLineDebug()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.RunInLine, (short)1);
        }

        /// <summary>
        /// 输入皮带关闭  --调试使用
        /// </summary>
        /// <param name="group"></param>
        public static void RunInLineDebugOff()
        {
            if (!IsCon)
            {
                Open();
            }

            MelsecPLC.WriteAsync(PLCAddrModel.RunInLine, (short)0);
        }

        /// <summary>
        /// 转向皮带运行  --调试使用
        /// </summary>
        /// <param name="group"></param>
        public static void RunReturnLineDebug()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.RunReturnLine, (short)1);
        }
        /// <summary>
        /// 转向皮带停止  --调试使用
        /// </summary>
        /// <param name="group"></param>
        public static void RunReturnLineDebugOff()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.RunReturnLine, (short)0);
        }
        /// <summary>
        /// 扫码皮带转动
        /// </summary>
        public static void RunScanOn()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.RunScan, (short)1);
        }
        /// <summary>
        /// 扫码皮带停止
        /// </summary>
        public static void RunScanOff()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.RunScan, (short)0);
        }
        /// <summary>
        /// 挡板A
        /// 0：关闭 1：打开
        /// </summary>
        /// <param name="ta"></param>
        public static void RunTA(int ta)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.TA, (short)ta);
        }
        /// <summary>
        /// 挡板B
        /// 0：关闭 1：打开
        /// </summary>
        /// <param name="ta"></param>
        public static void RunTB(int ta)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.TB, (short)ta);
        }
        /// <summary>
        /// 托盘A皮带正反转
        /// </summary>
        /// <param name="group">模组</param>
        /// <param name="IsForward">正反转 0:停止 1：正转，2：反转</param>
        public static void RunTray(int IsForward)
        {
            if (!IsCon)
            {
                Open();
            }

            MelsecPLC.WriteAsync(PLCAddrModel.RunTrayA, (short)IsForward);
        }
        /// <summary>
        /// 托盘B皮带正反转
        /// </summary>
        /// <param name="group">模组</param>
        /// <param name="IsForward">正反转 0:停止 1：正转，2：反转</param>
        public static void RunTrayB(int IsForward)
        {
            if (!IsCon)
            {
                Open();
            }

            MelsecPLC.WriteAsync(PLCAddrModel.RunTrayB, (short)IsForward);
        }

        /// <summary>
        /// 设置X轴速度
        /// </summary>
        /// <param name="group"></param>
        /// <param name="Speed"></param>
        public static void SetXSpeed(int Speed)
        {
            //if (!ACon)
            //{
            //    PlcConnectA();
            //}
            //if (!BCon)
            //{
            //    PlcConnectB();
            //}
            //if (group.Equals(EnumStockGroup.A))
            //{
            //    AFXCPU.WriteAsync(PLCAddrModel.SetXSpeed, (short)Speed);
            //}
            //else if (group.Equals(EnumStockGroup.B))
            //{
            //    BFXCPU.WriteAsync(PLCAddrModel.SetXSpeed, (short)Speed);
            //}

        }


        /// <summary>
        /// 设置Z轴速度
        /// </summary>
        /// <param name="group"></param>
        /// <param name="Speed"></param>
        public static void SetZSpeed( int Speed)
        {
            //if (!ACon)
            //{
            //    PlcConnectA();
            //}
            //if (!BCon)
            //{
            //    PlcConnectB();
            //}
            //if (group.Equals(EnumStockGroup.A))
            //{
            //    AFXCPU.WriteAsync(PLCAddrModel.SetZSpeed, (short)Speed);
            //}
            //else if (group.Equals(EnumStockGroup.B))
            //{
            //    BFXCPU.WriteAsync(PLCAddrModel.SetZSpeed, (short)Speed);
            //}
        }

        /// <summary>
        /// 整体回原点
        /// </summary>
        /// <param name="group"> 模组</param>
        public static void RunToOrgin()
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BackToOrigin, (short)1);
        }
        #endregion

        #region  设备监控方法
        public static void StartMonitor()
        {
            //ReadXPosLimit();
            //ReadXNegLimit();

            //ReadZPosLimit();
            //ReadZNegLimit();

            //ReadXOrgin();
            //ReadZOrgin();
            ReadAllToOrgin();
            ReadInlineStartPoint();
            ReadInlineEndPoint();
            ReadReturnLinePoint();
            ReadTrayBeginPoint();
            ReadTrayMiddlePoint();
            ReadTrayFinishPoint();
            ReadTowTrackSafe();
            ReadXMotor();
            ReadZMotor();


        }

        /// <summary>
        /// A模组回原点
        /// </summary>
        /// <returns></returns>
        public static short ReadAllToOrgin()
        {
            if (!IsCon)
            {
                Open();
            }

            var OrginA = MelsecPLC.ReadInt16Async(PLCAddrModel.OriginStates, 1);
            AppsettingUnits.SignalModel.AllToOrgin = OrginA.Result.Content[0];
            return OrginA.Result.Content[0];
        }
        /// <summary>
        /// 清除进入一袋
        /// </summary>
        /// <param name="Point"></param>
        public static void WriteInPoint(int Point)
        {
            if (!IsCon)
            {
                Open();
            }

            var res = MelsecPLC.Write(PLCAddrModel.InLineStartPoint, (short)Point);
            if (!res.IsSuccess)
            {
                _log.Error("清除错误");
            }
            else
            {
                _log.Info("清除进入一袋水信号");
            }
        }


        static short OldStates = 1;
        /// <summary>
        /// 获取入口点状态
        /// </summary>
        public static OperateResult<short[]> GetInLinePoint()
        {
            if (!IsCon)
            {
                Open();
            }

           // short NewStates = 0;
            AppsettingUnits.SignalModel.InLinePoint = false;
          var NewStates= MelsecPLC.ReadInt16(PLCAddrModel.InLineStartPoint, 1);

            // _log.Debug("入队信号：" + NewStates.Content[0]);
            //_log.Info("入队信号:" + NewStates.Content[0] + DateTime.Now.ToString("yyyy/MM/dd h:mm:ss.fff"));

            if (NewStates.Content[0]==1&&NewStates.IsSuccess)
            {
                AppsettingUnits.SignalModel.InLinePoint = true;
                OldStates = NewStates.Content[0];
            }
            OldStates = NewStates.Content[0];
            return NewStates;
        }

        static int EndDrugOldStates = 0;
        /// <summary>
        /// 获取是否是最后一袋
        /// </summary>
        public static async Task<OperateResult<short[]>> GetEndDrugPoint()
        {
            if (!IsCon)
            {
                Open();
            }
            // short NewStates = 0;
            AppsettingUnits.SignalModel.EndDrugPoint = false;
            //var NewStates =await AFXCPU.ReadInt16Async(PLCAddrModel.IfEndDrug,1);
            //if (NewStates.Content[0] == 1 && NewStates.IsSuccess)
            //{
            //    EndDrugOldStates = NewStates.Content[0];
            //    AppsettingUnits.SignalModel.EndDrugPoint = true;
            //}
            //EndDrugOldStates = NewStates.Content[0];

            return null;
        }
        /// <summary>
        /// 获取回原点状态
        /// </summary>
        public static async Task<OperateResult<short[]>> GetbackOrgState()
        {
            if (!IsCon)
            {
                Open();
            }
            // short NewStates = 0;
            var NewStates =await MelsecPLC.ReadInt16Async(PLCAddrModel.OriginStates,1);
            AppsettingUnits.SignalModel.BackOrgState = NewStates.Content[0];
            return NewStates;
        }
        //============================== 监控PLC地址 ==============================

        /// <summary>
        ///  读取X轴正极限  AB双模组(AX轴正极限)
        /// </summary>
        /// <param name="XPosLimitA">A模组状态</param>
        /// <param name="XPosLimitB">B模组状态</param>
        public static void ReadXPosLimit()
        {
            if (!IsCon)
            {
                Open();
            }
            var PosLimit = MelsecPLC.ReadInt16Async(PLCAddrModel.XPositiveLimit);
            AppsettingUnits.SignalModel.XPosLimit = PosLimit.Result.Content;
        }

        /// <summary>
        /// 读取X轴反极限  AB双模组(AX轴负极限)
        /// </summary>
        /// <param name="ZPosLimitA">A模组状态</param>
        /// <param name="ZPosLimitB">B模组状态</param>
        public static void ReadXNegLimit()
        {
            if (!IsCon)
            {
                Open();
            }
            var NegLimit = MelsecPLC.ReadInt16Async(PLCAddrModel.XNegativeLimit,1);
            AppsettingUnits.SignalModel.XNegLimit = NegLimit.Result.Content[0];
        }
        
        #region New
        /// <summary>
        /// 读取AX轴正极限
        /// </summary>
        /// <returns></returns>
        public static string ReadAX1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.XPositiveLimit);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AX轴负极限
        /// </summary>
        /// <returns></returns>
        public static string ReadAX0()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.XNegativeLimit);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AX轴速度
        /// </summary>
        /// <returns></returns>
        public static string ReadSpeedAX()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.SpeedAX);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴速度
        /// </summary>
        /// <returns></returns>
        public static string ReadSpeedAZ()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.SpeedAZ);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BX轴速度
        /// </summary>
        /// <returns></returns>
        public static string ReadSpeedBX()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.SpeedBX);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴速度
        /// </summary>
        /// <returns></returns>
        public static string ReadSpeedBZ()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.SpeedBZ);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取进入一袋药信号滤波时间
        /// </summary>
        /// <returns></returns>
        public static string ReadFilterTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.FilterTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取输入出药时间
        /// </summary>
        /// <returns></returns>
        public static string ReadInputTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.InputTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取扫码入药时间
        /// </summary>
        /// <returns></returns>
        public static string ReadScanInTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ScanInTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取扫码出药时间
        /// </summary>
        /// <returns></returns>
        public static string ReadScanOutTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ScanOutTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取转向入药时间
        /// </summary>
        /// <returns></returns>
        public static string ReadTurnInTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.TurnInTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取转向出药时间
        /// </summary>
        /// <returns></returns>
        public static string ReadTurnOutTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.TurnOutTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘入药时间
        /// </summary>
        /// <returns></returns>
        public static string ReadPalletInTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.PalletInTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘出药容错时间
        /// </summary>
        /// <returns></returns>
        public static string ReadErrorTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ErrorTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘出药延迟时间
        /// </summary>
        /// <returns></returns>
        public static string ReadDelayTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.DelayTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘出药超时时间
        /// </summary>
        /// <returns></returns>
        public static string ReadOutTime()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.OutTime);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取模组数量1/2
        /// </summary>
        /// <returns></returns>
        public static string ReadModuleNum()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ModuleNum);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取储位数量38/49
        /// </summary>
        /// <returns></returns>
        public static string ReadStorageNum()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.StorageNum);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AX轴原点
        /// </summary>
        /// <returns></returns>
        public static string ReadAXY()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.XOrigin);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AX轴使能
        /// </summary>
        /// <returns></returns>
        public static string ReadAXS()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.XMotorMake);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴正极限
        /// </summary>
        /// <returns></returns>
        public static string ReadAZ1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ZNegativeLimit);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴负极限
        /// </summary>
        /// <returns></returns>
        public static string ReadAZ0()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ZPositiveLimit);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴原点
        /// </summary>
        /// <returns></returns>
        public static string ReadAZY()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ZOrigin);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴使能
        /// </summary>
        /// <returns></returns>
        public static string ReadAZS()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ZMotorMake);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BX轴正极限
        /// </summary>
        /// <returns></returns>
        public static string ReadBX1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BX1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BX轴负极限
        /// </summary>
        /// <returns></returns>
        public static string ReadBX0()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BX0);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BX轴原点
        /// </summary>
        /// <returns></returns>
        public static string ReadBXY()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BXy);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BX轴使能
        /// </summary>
        /// <returns></returns>
        public static string ReadBXS()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BXs);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴正极限,上方
        /// </summary>
        /// <returns></returns>
        public static string ReadBZ1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BZ1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴负极限,下方
        /// </summary>
        /// <returns></returns>
        public static string ReadBZ0()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BZ0);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴原点
        /// </summary>
        /// <returns></returns>
        public static string ReadBZY()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BZy);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AX轴当前位置脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowAX()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.NowAX);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴当前位置脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowAZ()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.NowAZ);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BX轴当前位置脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBX()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.NowBX);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴当前位置脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBZ()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.NowBZ);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 写入储位号
        /// </summary>
        /// <param name="value"></param>
        public static void WriteStorage(short value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.WriteLoc, value);
        }
        /// <summary>
        /// 读取AX轴正极限脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBoundsAX1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BoundsAX1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 写入AX轴正极限脉冲值
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBoundsAX1(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BoundsAX1, value);
        }
        /// <summary>
        /// 写入AX轴负极限脉冲值
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBoundsAX0(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BoundsAX0, value);
        }
        /// <summary>
        /// 写入AZ轴正极限脉冲值
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBoundsAZ1(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BoundsAZ1, value);
        }
        /// <summary>
        /// 写入AX轴速度
        /// </summary>
        /// <param name="value"></param>
        public static void WriteSpeedAX(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.SpeedAX, value);
        }
        /// <summary>
        /// 写入AZ轴速度
        /// </summary>
        /// <param name="value"></param>
        public static void WriteSpeedAZ(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.SpeedAZ, value);
        }
        /// <summary>
        /// 写入BX轴速度
        /// </summary>
        /// <param name="value"></param>
        public static void WriteSpeedBX(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.SpeedBX, value);
        }
        /// <summary>
        /// 写入BZ轴速度
        /// </summary>
        /// <param name="value"></param>
        public static void WriteSpeedBZ(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.SpeedBZ, value);
        }
        /// <summary>
        /// 写入进入一袋药信号滤波时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteFilterTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.FilterTime, (short)value);
        }
        /// <summary>
        /// 写入输入出药时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteInputTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.InputTime, (short)value);
        }
        /// <summary>
        /// 写入扫码入药时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteScanInTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.ScanInTime, (short)value);
        }
        /// <summary>
        /// 写入扫码出药时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteScanOutTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.ScanOutTime, (short)value);
        }
        /// <summary>
        /// 写入转向入药时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteTurnInTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.TurnInTime, (short)value);
        }
        /// <summary>
        /// 写入转向出药时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteTurnOutTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.TurnOutTime, (short)value);
        }
        /// <summary>
        /// 写入托盘入药时间
        /// </summary>
        /// <param name="value"></param>
        public static void WritePalletInTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.PalletInTime, (short)value);
        }
        /// <summary>
        /// 写入托盘出药容错时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteErrorTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.ErrorTime, (short)value);
        }
        /// <summary>
        /// 写入托盘出药延迟时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteDelayTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.DelayTime, (short)value);
        }
        /// <summary>
        /// 写入托盘出药超时时间
        /// </summary>
        /// <param name="value"></param>
        public static void WriteOutTime(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.OutTime, (short)value);
        }
        /// <summary>
        /// 写入模组数量1/2
        /// </summary>
        /// <param name="value"></param>
        public static void WriteModuleNum(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.ModuleNum, (short)value);
        }
        /// <summary>
        /// 写入储位数量38/49
        /// </summary>
        /// <param name="value"></param>
        public static void WriteStorageNum(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.StorageNum, (short)value);
        }
        /// <summary>
        /// 写入AZ轴负极限脉冲值
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBoundsAZ0(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BoundsAZ0, value);
        }
        /// <summary>
        /// 写入BZ轴正极限脉冲值
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBoundsBZ1(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BoundsBZ1, value);
        }
        /// <summary>
        /// 写入BZ轴负极限脉冲值
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBoundsBZ0(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BoundsBZ0, value);
        }
        /// <summary>
        /// 写入BX轴正极限脉冲值
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBoundsBX1(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BoundsBX1, value);
        }
        /// <summary>
        /// 写入X轴1列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC1(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C1, value);
        }
        /// <summary>
        /// 写入X轴2列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC2(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C2, value);
        }
        /// <summary>
        /// 写入X轴3列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC3(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C3, value);
        }
        /// <summary>
        /// 写入X轴4列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC4(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C4, value);
        }
        /// <summary>
        /// 写入X轴5列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC5(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C5, value);
        }
        /// <summary>
        /// 写入X轴6列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC6(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C6, value);
        }
        /// <summary>
        /// 写入X轴7列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC7(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C7, value);
        }
        /// <summary>
        /// 写入X轴8列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC8(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C8, value);
        }
        /// <summary>
        /// 写入X轴9列
        /// </summary>
        /// <param name="value"></param>
        public static void WriteC9(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.C9, value);
        }
        /// <summary>
        /// 写入AZ轴1层
        /// </summary>
        /// <param name="value"></param>
        public static void WriteAR1(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.AR1, value);
        }
        /// <summary>
        /// 写入AZ轴2层
        /// </summary>
        /// <param name="value"></param>
        public static void WriteAR2(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.AR2, value);
        }
        /// <summary>
        /// 写入AZ轴3层
        /// </summary>
        /// <param name="value"></param>
        public static void WriteAR3(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.AR3, value);
        }
        /// <summary>
        /// 写入BZ轴1层
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBR1(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BR1, value);
        }
        /// <summary>
        /// 写入BZ轴2层
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBR2(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BR2, value);
        }
        /// <summary>
        /// 写入BZ轴3层
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBR3(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BR3, value);
        }
        /// <summary>
        /// 写入托盘AX轴药品输入位置
        /// </summary>
        /// <param name="value"></param>
        public static void WriteDrugAx(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.DrugAx, value);
        }
        /// <summary>
        /// 写入托盘AZ轴药品输入位置
        /// </summary>
        /// <param name="value"></param>
        public static void WriteDrugAz(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.DrugAz, value);
        }
        /// <summary>
        /// 写入托盘BX轴药品输入位置
        /// </summary>
        /// <param name="value"></param>
        public static void WriteDrugBx(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.DrugBx, value);
        }
        /// <summary>
        /// 写入托盘BZ轴药品输入位置
        /// </summary>
        /// <param name="value"></param>
        public static void WriteDrugBz(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.DrugBz, value);
        }
        /// <summary>
        /// 写入BX轴负极限脉冲值
        /// </summary>
        /// <param name="value"></param>
        public static void WriteBoundsBX0(int value)
        {
            if (!IsCon)
            {
                Open();
            }
            MelsecPLC.WriteAsync(PLCAddrModel.BoundsBX0, value);
        }
        /// <summary>
        /// 读取AX轴负极限脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBoundsAX0()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BoundsAX0);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘AX轴安全位置
        /// </summary>
        /// <returns></returns>
        public static string ReadSafeAX()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.SafeAX);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘AZ轴安全位置
        /// </summary>
        /// <returns></returns>
        public static string ReadSafeAZ()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.SafeAZ);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘BX轴安全位置
        /// </summary>
        /// <returns></returns>
        public static string ReadSafeBX()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.SafeBX);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘BZ轴安全位置
        /// </summary>
        /// <returns></returns>
        public static string ReadSafeBZ()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.SafeBZ);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘AX轴药品输入位置
        /// </summary>
        /// <returns></returns>
        public static string ReadDrugAx()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.DrugAx);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘AZ轴药品输入位置
        /// </summary>
        /// <returns></returns>
        public static string ReadDrugAz()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.DrugAz);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘BX轴药品输入位置
        /// </summary>
        /// <returns></returns>
        public static string ReadDrugBx()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.DrugBx);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取托盘BZ轴药品输入位置
        /// </summary>
        /// <returns></returns>
        public static string ReadDrugBz()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.DrugBz);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴负极限脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBoundsAZ0()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BoundsAZ0);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴正极限脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBoundsAZ1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BoundsAZ1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴正极限脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBoundsBZ1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BoundsBZ1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴负极限脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBoundsBZ0()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BoundsBZ0);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BX轴负极限脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBoundsBX0()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BoundsBX0);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BX轴正极限脉冲值
        /// </summary>
        /// <returns></returns>
        public static string ReadNowBoundsBX1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BoundsBX1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴使能
        /// </summary>
        /// <returns></returns>
        public static string ReadBZS()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BZs);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取A托盘入口传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadATI()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ATI);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取A托盘中间传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadATM()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ATM);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取A托盘出口传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadATO()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ATO);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取B托盘入口传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadBTI()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BTI);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取B托盘中间传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadBTM()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BTM);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取B托盘出口传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadBTO()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.BTO);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取扫码出口传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadScanOut()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ScanOut);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取扫码入口传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadScanImp()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ScanImp);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取扫码中间传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadScanMiddle()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.ScanMiddle);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取挡板A
        /// </summary>
        /// <returns></returns>
        public static string ReadDBA()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.DBA);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴1列
        /// </summary>
        /// <returns></returns>
        public static string ReadC1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴2列
        /// </summary>
        /// <returns></returns>
        public static string ReadC2()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C2);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴3列
        /// </summary>
        /// <returns></returns>
        public static string ReadC3()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C3);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴4列
        /// </summary>
        /// <returns></returns>
        public static string ReadC4()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C4);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴5列
        /// </summary>
        /// <returns></returns>
        public static string ReadC5()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C5);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴6列
        /// </summary>
        /// <returns></returns>
        public static string ReadC6()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C6);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴7列
        /// </summary>
        /// <returns></returns>
        public static string ReadC7()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C7);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴8列
        /// </summary>
        /// <returns></returns>
        public static string ReadC8()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C8);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取X轴9列
        /// </summary>
        /// <returns></returns>
        public static string ReadC9()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.C9);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴1层
        /// </summary>
        /// <returns></returns>
        public static string ReadAR1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.AR1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴2层
        /// </summary>
        /// <returns></returns>
        public static string ReadAR2()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.AR2);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取AZ轴3层
        /// </summary>
        /// <returns></returns>
        public static string ReadAR3()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.AR3);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴1层
        /// </summary>
        /// <returns></returns>
        public static string ReadBR1()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BR1);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴2层
        /// </summary>
        /// <returns></returns>
        public static string ReadBR2()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BR2);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取BZ轴3层
        /// </summary>
        /// <returns></returns>
        public static string ReadBR3()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt32Async(PLCAddrModel.BR3);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取挡板B
        /// </summary>
        /// <returns></returns>
        public static string ReadDBB()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.DBB);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取转向传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadTurn()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.Turn);
            return res.Result.Content.ToString();
        }
        /// <summary>
        /// 读取防撞传感器
        /// </summary>
        /// <returns></returns>
        public static string ReadAC()
        {
            if (!IsCon)
            {
                Open();
            }
            var res = MelsecPLC.ReadInt16Async(PLCAddrModel.AC);
            return res.Result.Content.ToString();
        }
        #endregion


        /// <summary>
        ///  读取Z轴正极限  AB双模组
        /// </summary>
        /// <param name="XPosLimitA">A模组状态</param>
        /// <param name="XPosLimitB">B模组状态</param>
        public static void ReadZPosLimit()
        {
            if (!IsCon)
            {
                Open();
            }

            var PosLimit = MelsecPLC.ReadInt16Async(PLCAddrModel.ZPositiveLimit);
            AppsettingUnits.SignalModel.ZPosLimit = PosLimit.Result.Content;
        }

        /// <summary>
        /// 读取Z轴反极限  AB双模组
        /// </summary>
        /// <param name="ZPosLimitA">A模组状态</param>
        /// <param name="ZPosLimitB">B模组状态</param>
        public static void ReadZNegLimit()
        {
            if (!IsCon)
            {
                Open();
            }

            var NegLimit = MelsecPLC.ReadInt16Async(PLCAddrModel.ZNegativeLimit);
            AppsettingUnits.SignalModel.ZNegLimit = NegLimit.Result.Content;
        }


        /// <summary>
        /// 读取X轴原点
        /// </summary>
        /// <param name="XOrginA">A模组状态</param>
        /// <param name="XOrginB">B模组状态</param>
        public static void ReadXOrgin()
        {
            if (!IsCon)
            {
                Open();
            }
            var XOrgin = MelsecPLC.ReadInt16Async(PLCAddrModel.XOrigin);
            AppsettingUnits.SignalModel.XOrgin = XOrgin.Result.Content;
        }


        /// <summary>
        /// 读取Z轴原点
        /// </summary>
        /// <param name="ZOrginA">A模组状态</param>
        /// <param name="ZOrginB">B模组状态</param>
        public static void ReadZOrgin()
        {
            if (!IsCon)
            {
                Open();
            }
            var ZOrgin = MelsecPLC.ReadInt16Async(PLCAddrModel.ZOrigin);
            AppsettingUnits.SignalModel.ZOrgin = ZOrgin.Result.Content;
        }


        /// <summary>
        /// 两轴距离过近传感器  0 距离过近   1  正在运行
        /// </summary>
        public static void ReadTowTrackSafe()
        {
            if (!IsCon)
            {
                Open();
            }
            var STowTrackSafe = MelsecPLC.ReadInt16Async(PLCAddrModel.RailSafety);
            AppsettingUnits.SignalModel.STowTrackSafe = STowTrackSafe.Result.Content;

        }

        /// <summary>
        /// 输入皮带开始位置
        /// </summary>
        public static void ReadInlineStartPoint()
        {
            if (!IsCon)
            {
                Open();
            }
            var SInlineStartPoint = MelsecPLC.ReadInt16Async(PLCAddrModel.InLineBeginPoint);
            AppsettingUnits.SignalModel.SInlineStartPoint = SInlineStartPoint.Result.Content;

        }

        /// <summary>
        /// 输入皮带结束位置
        /// </summary>
        public static void ReadInlineEndPoint()
        {
            if (!IsCon)
            {
                Open();
            }
            var SInlineEndPoint = MelsecPLC.ReadInt16Async(PLCAddrModel.InLineFinishPoint);
            AppsettingUnits.SignalModel.SInlineEndPoint = SInlineEndPoint.Result.Content;
        }


        /// <summary>
        /// 转向皮带传感器
        /// </summary>
        /// <param name="ReturnLinePoint"></param>
        public static void ReadReturnLinePoint()
        {
            if (!IsCon)
            {
                Open();
            }
            var SReturnLinePoint = MelsecPLC.ReadInt16Async(PLCAddrModel.TrunLinePoint);
            AppsettingUnits.SignalModel.SReturnLinePoint = SReturnLinePoint.Result.Content;

        }



        /// <summary>
        /// 托盘开始位置
        /// </summary>
        /// <param name="TrayBeginPoint"></param>
        public static void ReadTrayBeginPoint()
        {
            if (!IsCon)
            {
                Open();
            }
            var STrayBeginPoint = MelsecPLC.ReadInt16Async(PLCAddrModel.TrayBeginPoint);
            AppsettingUnits.SignalModel.STrayBeginPoint = STrayBeginPoint.Result.Content;
        }

        /// <summary>
        /// 托盘中间位置
        /// </summary>
        /// <param name="TrayMiddlePoint"></param>
        public static void ReadTrayMiddlePoint()
        {
            if (!IsCon)
            {
                Open();
            }
            var STrayMiddlePoint = MelsecPLC.ReadInt16Async(PLCAddrModel.TrayMiddlePoint);
            AppsettingUnits.SignalModel.STrayMiddlePoint = STrayMiddlePoint.Result.Content;
        }


        /// <summary>
        /// 托盘结束位置
        /// </summary>
        /// <param name="TrayMiddlePoint"></param>
        public static void ReadTrayFinishPoint()
        {
            if (!IsCon)
            {
                Open();
            }
            var STrayFinishPoint = MelsecPLC.ReadInt16Async(PLCAddrModel.TrayFinishPoint);
            AppsettingUnits.SignalModel.STrayFinishPoint = STrayFinishPoint.Result.Content;
        }


        /// <summary>
        /// X电机使能
        /// </summary>
        public static void ReadXMotor()
        {
            if (!IsCon)
            {
                Open();
            }
          
            var SXMotor = MelsecPLC.ReadInt16Async(PLCAddrModel.XMotorMake);
            AppsettingUnits.SignalModel.SXMotor = SXMotor.Result.Content;
        }



        /// <summary>
        /// Z电机使能
        /// </summary>
        public static void ReadZMotor()
        {
            if (!IsCon)
            {
                Open();
            }
            var SZMotor = MelsecPLC.ReadInt16Async(PLCAddrModel.ZMotorMake);
            AppsettingUnits.SignalModel.SZMotor = SZMotor.Result.Content;
        }






        #endregion

        #region 看门狗 PLC存活检测

        public static short GetPlcLifeCmd()
        {
            try
            {
                //short PLCLife = 0;
                var PLCLife = MelsecPLC.ReadInt16Async(PLCAddrModel.PLCLife);
                //_log.Debug(PLCLife);
                return PLCLife.Result.Content;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }


        }



        #endregion

        #region 看门狗 PLC存活检测
        public static void GetSoftWareLifeCmd()
        {
            MelsecPLC.WriteAsync(PLCAddrModel.SoftWareLife, (short)1);
            //_log.Debug("写入软件存活");
        }
        #endregion
    }
}
